package com.wd.health.view.activity;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.wd.health.R;
import com.gyf.immersionbar.ImmersionBar;

public class MainActivity extends AppCompatActivity {
    private ImageView img_start;
    private TextView tv_time;

    private int time = 3;
    private Handler handler = new Handler(){
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            //倒计时为0跳转
            if (time==0){
                Intent intent = new Intent(MainActivity.this,StartActivity.class);
                startActivity(intent);
                //清除
                handler.removeCallbacksAndMessages(msg);
                //销毁
                finish();
            }else {
                time--;
                tv_time.setText(time+"");
                sendEmptyMessageDelayed(1,1000);
            }
        }
    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        img_start = findViewById(R.id.img_start);
        tv_time = findViewById(R.id. tv_start_time);
        ImmersionBar.with(this).init();
        img_start.setImageResource(R.mipmap.qidong);

        handler.sendEmptyMessageDelayed(1,1000);
        tv_time.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this,StartActivity.class);
                startActivity(intent);
                handler.removeCallbacksAndMessages(null);
                finish();
            }
        });
    }
}